Advertisement
pleasedontcode

Reminder System rev_01

May 18th, 2024
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Reminder System
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2024-05-18 07:59:42
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* ring buzzer and motor every 1 minute for 5 */
  21.     /* minutes. if push button is pressed while the */
  22.     /* buzzer is active, turn off the countdown for 10 */
  23.     /* minutes, else keep repeating it.     Also display */
  24.     /* "Please Take Your Medicine" while the buzzer is */
  25.     /* active */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27.     /* ring buzzer and motor every 1 minute for 5 */
  28.     /* minutes. if push button is pressed while the */
  29.     /* buzzer is active, turn off the countdown for 10 */
  30.     /* minutes, else keep repeating it.     Also display */
  31.     /* "Please Take Your Medicine" while the buzzer is */
  32.     /* active */
  33. /****** END SYSTEM REQUIREMENTS *****/
  34.  
  35. /****** DEFINITION OF LIBRARIES *****/
  36. #include <Wire.h>
  37. #include <Adafruit_SSD1306.h>   //https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
  38. #include <U8g2_for_Adafruit_GFX.h>  //https://github.com/olikraus/U8g2_for_Adafruit_GFX
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43. void updateOutputs(void);
  44. void ringBuzzerAndMotor(void);
  45.  
  46. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  47. const uint8_t Reed_PushButton_PIN_D3 = 3;
  48. const uint8_t Reed_PushButton_PIN_D4 = 4;
  49.  
  50. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  51. const uint8_t Buzzer_PassiveBuzzer_Signal_PIN_D2 = 2;
  52. const uint8_t Vibrator_LED_PIN_D5 = 5;
  53.  
  54. /***** DEFINITION OF I2C PINS *****/
  55. const uint8_t Screen_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
  56. const uint8_t Screen_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
  57. const uint8_t Screen_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 60;
  58.  
  59. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  60. bool Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
  61. bool Vibrator_LED_PIN_D5_rawData = 0;
  62.  
  63. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  64. float Buzzer_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;
  65. float Vibrator_LED_PIN_D5_phyData = 0.0;
  66.  
  67. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  68. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, Screen_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
  69.  
  70. bool pushButtonPressed = false;
  71. unsigned long lastPressTime = 0;
  72. unsigned long buzzerStartTime = 0;
  73. const unsigned long buzzerInterval = 60000; // 1 minute
  74. const unsigned long buzzerDuration = 300000; // 5 minutes
  75. const unsigned long pauseDuration = 600000; // 10 minutes
  76.  
  77. void setup(void)
  78. {
  79.     // put your setup code here, to run once:
  80.     pinMode(Reed_PushButton_PIN_D3, INPUT_PULLUP);
  81.     pinMode(Reed_PushButton_PIN_D4, INPUT_PULLUP);
  82.     pinMode(Buzzer_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
  83.     pinMode(Vibrator_LED_PIN_D5, OUTPUT);
  84.  
  85.     display.begin(SSD1306_SWITCHCAPVCC, Screen_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
  86.     display.display(); // Show initial display buffer contents on the screen
  87. }
  88.  
  89. void loop(void)
  90. {
  91.     // put your main code here, to run repeatedly:
  92.     updateOutputs(); // Refresh output data
  93.     ringBuzzerAndMotor(); // Check and ring buzzer and motor
  94. }
  95.  
  96. void updateOutputs()
  97. {
  98.     digitalWrite(Buzzer_PassiveBuzzer_Signal_PIN_D2, Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData);
  99.     digitalWrite(Vibrator_LED_PIN_D5, Vibrator_LED_PIN_D5_rawData);
  100. }
  101.  
  102. void ringBuzzerAndMotor()
  103. {
  104.     unsigned long currentTime = millis();
  105.  
  106.     if (!pushButtonPressed) {
  107.         if (currentTime - buzzerStartTime >= buzzerInterval) {
  108.             Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 1;
  109.             Vibrator_LED_PIN_D5_rawData = 1;
  110.             display.clearDisplay();
  111.             display.setTextSize(1);
  112.             display.setTextColor(WHITE);
  113.             display.setCursor(0, 0);
  114.             display.println("Please Take Your Medicine");
  115.             display.display();
  116.             buzzerStartTime = currentTime;
  117.         }
  118.  
  119.         if (currentTime - buzzerStartTime >= buzzerDuration) {
  120.             Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
  121.             Vibrator_LED_PIN_D5_rawData = 0;
  122.             display.clearDisplay();
  123.             display.display();
  124.             buzzerStartTime = currentTime;
  125.         }
  126.     } else {
  127.         if (currentTime - lastPressTime < pauseDuration) {
  128.             Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
  129.             Vibrator_LED_PIN_D5_rawData = 0;
  130.             display.clearDisplay();
  131.             display.display();
  132.         } else {
  133.             pushButtonPressed = false;
  134.         }
  135.     }
  136. }
  137.  
  138. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement